package action.bbs;

import java.io.UnsupportedEncodingException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import mybatis.conService.ServiceFactory;

import org.apache.ibatis.session.SqlSession;

import vo.ResultVO;
import vo.bbs.Comment_tVO;
import control.ActionInter;

public class ReplyAdd_A implements ActionInter{

	@Override
	public ResultVO excute(HttpServletRequest request,
			HttpServletResponse response) {
		// TODO Auto-generated method stub
		SqlSession ss = ServiceFactory.getFactory().openSession();
		
		ResultVO rvo = new ResultVO();
		Comment_tVO cvo = new Comment_tVO();
		try {
			request.setCharacterEncoding("utf-8");
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		int idx = ss.selectOne("commentAll");
		cvo.setIdx(idx);
		cvo.setWrite(request.getParameter("c_name"));
		cvo.setIp(request.getRemoteAddr());
		cvo.setContent(request.getParameter("c_content"));
		cvo.setBbs_idx(Integer.parseInt(request.getParameter("bbs_idx")));
		cvo.setPwd(request.getParameter("c_pwd"));
		
		int result = ss.insert("replyAdd", cvo);
		
		if(result != 1)
			 	return null ;
		
		ss.commit();
		request.setAttribute("cvo", cvo);
		rvo.setCmd("post");
		rvo.setUrl("bbs/replyAdd.jsp");//표현될 페이지
		
		return rvo;
	}

}
